package com.elitect.ftptransfer.dialog;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.view.ViewGroup.LayoutParams;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.elitect.ftptransfer.R;

/**
 * The dialog for show a message that can be updated later.
 * 
 * @author NgocTan
 * 
 */
public class InputTextDialog extends Dialog
{
    private EditText mViewInput;
    private Dialog mDialog;
    
    public interface InputListener
    {
        void onInputText(String text);
    }
    
    private InputListener mInputListener;

    public InputTextDialog(Context context, String title, InputListener inputListener)
    {
        super(context);
        mInputListener = inputListener;

        LinearLayout viewParent = new LinearLayout(context);
        viewParent.setPadding(5, 10, 5, 10);
        viewParent.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT));
        viewParent.setBackgroundColor(Color.WHITE);

        mViewInput = new EditText(context);
        mViewInput.setTextColor(Color.BLACK);
        mViewInput.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT));
        viewParent.addView(mViewInput);

        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setIcon(android.R.drawable.ic_dialog_info).setTitle(title).setView(
                viewParent).setPositiveButton(R.string.ok, new OnClickListener()
                {
                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {
                        mInputListener.onInputText(mViewInput.getText().toString());
                    }
                });
        mDialog = builder.create();
    }

    @Override
    public void show()
    {
        mDialog.show();
    }
}
